/// @tags: PersistedSegTree
#include <algorithm>
#include <cctype>
#include <cstdio>

namespace BlueQuantum {

int const N = 3e5 + 5;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Node {
  int ls, rs, sum;
} tr[N * 19];

int n, m, cnt;
int root[N], a[N], hash[N];

void insert(int val, int &x, int y, int l = 1, int r = *hash) {
  tr[x = ++cnt] = tr[y];
  tr[x].sum++;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (val <= mid) insert(val, tr[x].ls, tr[y].ls, l, mid);
  else
    insert(val, tr[x].rs, tr[y].rs, mid + 1, r);
}

int query(int k, int fnt, int bak, int l = 1, int r = *hash) {
  if (l == r) return hash[l];
  int lsum = tr[tr[bak].ls].sum - tr[tr[fnt].ls].sum,
      rsum = tr[tr[bak].rs].sum - tr[tr[fnt].rs].sum, res;
  int mid = (l + r) >> 1;
  if (lsum > k)
    if ((res = query(k, tr[fnt].ls, tr[bak].ls, l, mid)) > 0) return res;
  if (rsum > k)
    if ((res = query(k, tr[fnt].rs, tr[bak].rs, mid + 1, r)) > 0) return res;
  return -1;
}

inline int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) hash[i] = read(a[i]);
  std::sort(hash + 1, hash + n + 1);
  *hash = std::unique(hash + 1, hash + n + 1) - hash - 1;
  for (int i = 1; i <= n; ++i)
    insert(std::lower_bound(hash + 1, hash + *hash + 1, a[i]) - hash, root[i], root[i - 1]);
  for (int i = 1, a, b, c; i <= m; ++i) {
    read(a), read(b), read(c);
    printf("%d\n", query((b - a + 1) / c, root[a - 1], root[b]));
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("CF840D Destiny.in", "r", stdin);
  freopen("CF840D Destiny.out", "w", stdout);
#endif
#endif
  return BlueQuantum::main();
}